@extends("layouts.backend.webadmin")

<link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/layui/css/layui.css">
{{--<link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2.min.css">
<link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2totree.css">--}}
<script src="{{env('APP_ROOT')}}/assets/layui/layui.js"></script>

@section('content')

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">
                        <form method="POST" id="form" lay-filter="boardFilter" class="layui-form" action="{{ URL::route('admin.flaw.checkForm')
                        }}">
                            <div class="form-group">
                                <label for="vulsCategoryId">漏洞编号</label><br>
                                @foreach ($vuls as $lists)
                                    <blockquote id="vulsCategoryId" class="layui-elem-quote layui-quote-nm">
                                        {{$lists->vuls_number}}
                                    </blockquote>
                                @endforeach
                            </div>
                            @needsroles([2,3])
                            <div class="form-group">
                                <label for="vulsCategoryId">标题</label><br>
                                @foreach ($vuls as $lists)
                                    <blockquote id="vulsCategoryId" class="layui-elem-quote layui-quote-nm">
                                        {{$lists->title}}
                                    </blockquote>
                                @endforeach
                            </div>
                            @endauth

                            <div class="form-group">
                                <div class="layui-form-item">
                                    <label>副标题</label>
                                    <div>
                                        <input name="description" value="{{$vuls[0]->description}}" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="layui-form-item">
                                    <label>漏洞URL</label>
                                    <div>
                                        <input name="form_url" value="{{$vuls[0]->form_url}}" class="layui-input">
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="layui-form-item">
                                    <label>URL参数</label>
                                    <div>
                                        <input name="url_parms" value="{{$vuls[0]->url_parms}}" class="layui-input">
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="layui-form-item">
                                    <label>Payload</label>
                                    <div>
                                        <input name="payload" value="{{$vuls[0]->payload}}" class="layui-input">
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="vulsCategoryId">漏洞详情</label><br>
                                <blockquote class="layui-elem-quote layui-quote-nm" id="vulsCategoryId">
                                    {!!$vuls[0]->content  !!}
                                </blockquote>
                            </div>
                            <div class="form-group">
                                <label for="vulsCategoryId">参考资料</label><br>
                                @foreach($vuls[0]->ref as $ref)
                                    <div class="col-md-12">
                                        <a style="padding-left:15px;" target="_blank" href="{{route('knowledge.showpage',['id'=>$ref->id])}}">{{mb_substr($ref->title,0,50)}}</a>
                                    </div>
                                @endforeach
                            </div>

                            <div class="row">
                                <div class="col-md-4">
                                    <label for="categoryId">所属分类</label><br>
                                    <select class="form-control" id="categoryId" name="categoryId" lay-verify="">
                                        <option value="">--漏洞分类--</option>
                                        @foreach ($categorys as $cate)
                                            <option class="l{{$cate->num}} {{$cate->child=='yes'?'non-leaf':''}}"
                                                    data-pup="{{$cate->pid}}"
                                                    @if($cate->id==$vuls[0]->category_id)  selected @endif
                                                    value="{{$cate->id}}">{{$cate->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <label for="vulsCategoryId">选择应用 </label>
                                    <select class="form-control" id="vulsCategoryId" required name="allocation">
                                        <option value="">--选择应用--</option>
                                        @foreach ($list as $lists)
                                            <option @if($vuls[0]->app_id==$lists->id)  selected
                                                    @endif value="{{$lists->id}}">{{$lists->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <label for="level">漏洞评级</label><br>
                                    <select class="form-control" lay-filter="level" id="level" name="level">
                                        <option value="">--请选择评级--</option>
                                        @if($level)
                                            @foreach ($level as $lists)
                                                <option @if($lists->id==$vuls[0]->level_id)  selected @endif
                                                value="{{$lists->id}}">{{$lists->name}}</option>
                                            @endforeach
                                        @endif
                                    </select>
                                </div>
                            </div>
                            {{--编辑漏洞所属分类 -- start--}}
                            {{--<div class="form-group">
                                <label for="categoryId">所属分类</label><br>
                                <select class="form-control" id="categoryId" name="categoryId" lay-verify="">
                                    <option value="">--漏洞分类--</option>
                                    @foreach ($categorys as $cate)
                                        <option class="l{{$cate->num}} {{$cate->child=='yes'?'non-leaf':''}}"
                                                data-pup="{{$cate->pid}}"
                                                @if($cate->id==$vuls[0]->category_id)  selected @endif
                                                value="{{$cate->id}}">{{$cate->name}}</option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="vulsCategoryId">选择应用 </label>
                                <select class="form-control" id="vulsCategoryId" required name="allocation">
                                    <option value="">--选择应用--</option>
                                    @foreach ($list as $lists)
                                        <option @if($vuls[0]->app_id==$lists->id)  selected
                                                @endif value="{{$lists->id}}">{{$lists->name}}</option>
                                    @endforeach
                                </select>
                            </div>
                            --}}{{--编辑漏洞所属分类 -- end --}}{{--
                            <div class="form-group">
                                <label for="level">漏洞评级</label><br>
                                <select class="form-control" lay-filter="level" id="level" name="level">
                                    <option value="">--请选择评级--</option>
                                    @if($level)
                                        @foreach ($level as $lists)
                                            <option @if($lists->id==$vuls[0]->level_id)  selected @endif
                                            value="{{$lists->id}}">{{$lists->name}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </div>--}}
                            @if(!empty($vuls[0]->source))
                                @if($vuls[0]->source==1)
                                @else
                                    <div class="form-group">
                                        <div class="layui-form-item">
                                            <label>积分</label>
                                            <div>
                                                <input type="number" id="credit" min="{{$vuls[0]->min_integ}}" max="{{$vuls[0]->max_integ}}"  name="credit"  placeholder="请输入积分，积分为{{$vuls[0]->min_integ}}到{{$vuls[0]->max_integ}}范围内的整数" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                @endif
                            @endif
                            <div class="form-group">
                                <label>描述</label>
                                <textarea class="form-control" maxlength="255" required rows="3" placeholder="相关描述..."
                                          name="descriptions"></textarea>
                            </div>
                            <div class="form-group">
                                <div class="layui-form-item">
                                    <label>提交类型</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="type" value="check" title="审核" checked>
                                        <input type="radio" name="type" value="ignore" title="忽略">
                                        <input type="radio" name="type" value="effect" title="无影响">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                {{csrf_field()}}
                                <input type="hidden" name="id" value="{{$id}}">
                                <button class="layui-btn layui-btn-warm" lay-submit
                                        lay-filter="formDemo">提交
                                </button>
                            </div>
                            @if($record)
                                <div class="form-group">
                                    <label for="vulsCategoryId">修复过程</label>
                                    <blockquote class="layui-elem-quote layui-quote-nm">
                                        <ul class="layui-timeline">

                                            @foreach($record as $records)
                                                <li class="layui-timeline-item">
                                                    <i class="layui-icon layui-timeline-axis">&#xe63f;</i>
                                                    <div class="layui-timeline-content layui-text">
                                                        <h3 class="layui-timeline-title">
                                                            @if($records->created_at)
                                                                {{$records->created_at}}
                                                            @endif
                                                        </h3>
                                                        <ul>
                                                            @if($records->vuls_status)
                                                                <li>
                                                                    状态：{{$status[$records->vuls_status]['name']}}
                                                                </li>
                                                            @endif
                                                                @if($records->creatname)
                                                                    <li>
                                                                        创建者：{{$records->creatname}}({{$records->creal_name}})({{$records->phone}})
                                                                    </li>
                                                                @endif


                                                                @if($records->updatename)
                                                                    <li>
                                                                        更新者：{{$records->updatename}}({{$records->ureal_name}})({{$records->phone}})
                                                                    </li>
                                                                @endif
                                                            @if($records->reward)
                                                                <li>
                                                                    当前金币：{{$records->reward}}
                                                                </li>
                                                            @endif
                                                            @if($records->credit)
                                                                <li>
                                                                    当前积分：{{$records->credit}}
                                                                </li>
                                                            @endif
                                                            @if($records->content)
                                                                <li>
                                                                    说明：{{$records->content}}
                                                                </li>
                                                            @endif

                                                        </ul>
                                                    </div>
                                                </li>
                                            @endforeach

                                        </ul>
                                    </blockquote>
                                </div>
                            @endif

                        </form>
                        <input type="hidden" id="error"
                               value="@foreach ($errors->all() as $error){{ $error }}@endforeach">
                        @if(count($errors->all()))
                            <script type="text/javascript">
                                var message = $("#error").val();
                                layui.use('layer', function () {
                                    var layer = layui.layer;
                                    layer.open({
                                        title: '错误提示'
                                        , content: message
                                    });
                                });
                            </script>

                        @endif
                        <input type="hidden" id="errors" value="{{session('flow_error')}}">
                        @if(session('flow_error'))
                            <script type="text/javascript">
                                var message = $("#errors").val();
                                layui.use('layer', function () {
                                    var layer = layui.layer;
                                    layer.open({
                                        title: '错误提示'
                                        , content: message
                                    });
                                });
                            </script>

                        @endif
                    </div>
                </div>
            </div>
        </div>
    </section>

    <script>
        layui.use('form', function () {
            var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
            form.render();
            form.on('select(level)', function (data) {
                var level = $("#level").val()
                $.ajax({
                    type: 'POST',
                    url: "{{route('vuls.ajax')}}",//发送请求
                    data: {'_token': '{{csrf_token()}}', 'level': level},
                    dataType: "json",
                    success: function (result) {
                        if (result) {
                            $("#credit").attr('min',result[0].min_integ);
                            $("#credit").attr('max',result[0].max_integ);
                            var placeholder="请输入积分，积分为"+result[0].min_integ+"到"+result[0].max_integ+"范围内的整数"
                            $("#credit").attr('placeholder',placeholder);
                            layui.form.render('select','boardFilter');
                        }
                    }
                });
            });
        });

    </script>
@stop
{{--layui与select2Totree 只能用一个--}}
{{--
@section('javascript-end')
    <script src="{{env('APP_ROOT')}}/assets/select2/js/select2.min.js"></script>
    <script src="{{env('APP_ROOT')}}/assets/select2/js/select2totree.js"></script>
    <script>
        $(function(){
         $('#categoryId').select2ToTree({ width: '100%' });
        });
    </script>
@stop--}}
